﻿using System.Collections.Generic;
using System.Linq;

namespace Tuxedo.Compile
{
	internal class FieldDefinition : IFPClassMember
	{
		public string Name { get; private set; }
		public Visibility Visibility { get; private set; }
		public bool IsStatic { get; private set; }
		public UnverifiedType Type { get; private set; }
		public Expression DefaultValue { get; private set; }
		public bool IsConst { get; private set; }
		public override MemberAttribute[] Attributes { get { return this.attributes; } }
		private MemberAttribute[] attributes;

		public FieldDefinition(Visibility visibility, bool isStatic, string name, UnverifiedType outputType, Expression defaultValue, bool isConst, IList<MemberAttribute> attributes)
		{
			this.Visibility = visibility;
			this.IsStatic = isStatic;
			this.Name = name;
			this.Type = outputType;
			this.DefaultValue = defaultValue;
			this.IsConst = isConst;
			this.attributes = attributes.ToArray();

			if (isConst && defaultValue == null)
			{
				throw new System.Exception("Cannot have a const without a value");
			}
		}
	}
}
